import { ref, onMounted } from 'vue';
import { getRdsUrl, rdsRequestAsync } from './rdsServices';

export function useProRelatedNameHook() {
    const rdsUrl = getRdsUrl();

    const proPeriods = ref(null);
    const channels = ref(null);
    const proDefs = ref(null);
    const cardAccount = ref(null);
    const coupon = ref(null);
    const memberLAble = ref(null);


    const initAllName = async () => {
        const result = await rdsRequestAsync(rdsUrl.bcApi, '促销公共服务', 'GetProRelatedName', '');
        if (!result.HasException) {
            proPeriods.value = result.ObjectData.ds0;
            Object.defineProperty(proPeriods.value, '_name', {
                value: 'mapProPeriod',
                enumerable: false
            });

            channels.value = result.ObjectData.ds1;
            Object.defineProperty(channels.value, '_name', {
                value: 'mapChannel',
                enumerable: false
            });

            proDefs.value = result.ObjectData.ds2;
            Object.defineProperty(proDefs.value, '_name', {
                value: 'mapProDef',
                enumerable: false
            });
        }
        const CRMResult = await rdsRequestAsync(rdsUrl.bcApi, '促销公共服务', 'GetCRMRelatedName', '');
        if (!CRMResult.HasException) {
            cardAccount.value = CRMResult.ObjectData.c1;
            coupon.value = CRMResult.ObjectData.c2;
            memberLAble.value = CRMResult.ObjectData.c3;
        }
    };

    onMounted(async() => {
       await initAllName();
    });

    return {
        initAllName,
        mapProPeriod: proPeriods,
        mapChannel: channels,
        mapProDef: proDefs,
        cardAccount: cardAccount,
        coupon: coupon,
        memberLAble: memberLAble
    };
}
